﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace LogisticsDAL
{
    public  class PROC_Helper
    {
        /// <summary>
        /// 公共分页功能
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="primary"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="Fierd"></param>
        /// <param name="Count"></param>
        /// <returns></returns>
        public static DataTable Paging(string TableName, string primary, int pageindex, int pagesize,string Fierd, out int Count)
        {
            string sql = "UP_Pagination";
            SqlParameter[] pram =
            {
                new SqlParameter("@Tables",SqlDbType.VarChar,1000),
                new SqlParameter("@PrimaryKey",SqlDbType.VarChar,1000),
                new SqlParameter("@Sort",SqlDbType.VarChar,1000),
                new SqlParameter("@CurrentPage",SqlDbType.Int),
                new SqlParameter("@PageSize",SqlDbType.Int),
                new SqlParameter("@Fields",SqlDbType.VarChar,1000),
                new SqlParameter("@Filter",SqlDbType.VarChar,1000),
                new SqlParameter("@Group",SqlDbType.VarChar,1000),
                new SqlParameter("@TotalRecordCount",ParameterDirection.Output)
            };
            pram[0].Value = TableName;
            pram[1].Value = primary;
            pram[2].Value = "";
            pram[3].Value = pageindex;
            pram[4].Value = pagesize;
            pram[5].Value = "*";
            pram[6].Value = Fierd;
            pram[7].Value = "";
            pram[8].Direction = ParameterDirection.Output;
            DataTable read = DBHelper.GetTables(sql, pram);
            Count = Convert.ToInt32(pram[8].Value);
            return read;
        }


        public static int InstPage(string Behavior,int TypeID,int UserID,string Parameters,string ProcName,string IP,int IsExcePtion)
        {
            string sqlproc = "p_SysLogInset";
            SqlParameter[] pram =
            {
                new SqlParameter("@Behavior",Behavior),
                new SqlParameter("@TypeID",TypeID),
                new SqlParameter("@UserID",UserID),
                new SqlParameter("@Parameters",Parameters),
                new SqlParameter("@ProcName",ProcName),
                new SqlParameter("@IP",IP),
                new SqlParameter("@IsExcePtion",IsExcePtion)
            };
            int number = DBHelper.Number(sqlproc, pram);
            return number;
        }
    }
}
